import {defineStore} from 'pinia';
import {io} from "socket.io-client";
import {v4 as uuid} from "uuid";

const UseSocketStore = defineStore({
    id: 'UseSocketStore',

    state: () => ({
        info: 'pinia 可以使用',
        socket: null,
        screenStream: null,
    }),
    actions: {
        initSocketConnect(queryInfo) {
            this.socket = io("http://localhost:3001", {
                transports: ["websocket"],
                query: queryInfo
            });
            this.socket.on("connect", async () => {
                console.log('客户端的连接', this.socket.id)
            })
        },
        disconnectSocket() {
            this.socket.disconnect()
            this.socket = null
        },
        joinRooms(data) {
            this.socket.emit('join', data)
        }
    },
    // 开启数据缓存
    persist: true,
});
export default UseSocketStore;

